
package yunhe.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.JSONArray;

import yunhe.biz.StockMgrBiz;
import yunhe.biz.impl.StockMgrBizImpl;
import yunhe.entity.Taking;
@WebServlet(name="GetAllProLossServlet",urlPatterns="/GetAllProLossServlet")
public class GetAllProLossServlet extends HttpServlet
{
/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException, IOException
{
	doPost(req,resp);
}
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException ,IOException 
{
	StockMgrBiz smb= new StockMgrBizImpl();
	//查询最近的盘点单
	List<Taking> taking=smb.queryLatestTimeTak();

	if(taking.isEmpty()){
		PrintWriter out=resp.getWriter();	
		out.print("最近没有盘点单，请先进行盘点");
	}
	else{
	String takid=taking.get(0).getTakId();
	System.out.println(takid);

	//根据盘点表id查詢所有的盤點表中损益数量不等于0的数据
	List<Taking> list=smb.queryProLossPro(takid);
	System.out.println("==========");
	System.out.println(list.size());
	
	 JSONArray ja=new JSONArray();

	
	 if(!list.isEmpty()){
         for (int i=0;i<list.size();i++){
             Map<String,String> mss=new HashMap<String,String>();
             mss.put("takId",list.get(i).getTakId());
             mss.put("stoName",list.get(i).getStorage().getStoName());
             mss.put("proBarCode",list.get(i).getProduct().getProBarCode());
             mss.put("preinvCount",Integer.toString(list.get(i).getPretakNum()));
             mss.put("invCount",Integer.toString(list.get(i).getTakNum()));
             mss.put("proLossCount",Integer.toString(list.get(i).getPhaseNum()));
             mss.put("proLossMoney",Double.toString(list.get(i).getPhaseDollar()));
             ja.put(mss);
         }
     }
	 resp.getWriter().print("{\"total\":300,\"rows\":"+ja.toString()+"}");
	
}
}

}